﻿@page
@model IndexModel
@{
}
<div class="grants">
    <div class="row page-header">
        <div class="col-sm-10">
            <h1>
                Client Application Access
            </h1>
            <div>Below is the list of applications you have given access to and the names of the resources they have access to.</div>
        </div>
    </div>

    @if (Model.GrantsViewModel.Grants.Any() == false)
    {
        <div class="row">
            <div class="col-sm-8">
                <div class="alert alert-info">
                    You have not given access to any applications
                </div>
            </div>
        </div>
    }
    else
    {
        <form method="post">
            @for (var i = 0; i < Model.GrantsViewModel.Grants.Count; i++)
            {
                <div class="row grant">
                    <div class="col-sm-2">
                        @if (Model.GrantsViewModel.Grants[i].ClientLogoUrl != null)
                        {
                            <img src="@Model.GrantsViewModel.Grants[i].ClientLogoUrl">
                        }
                    </div>
                    <input asp-for="@Model.GrantsViewModel.Grants[i].ClientId"
                           type="hidden">
                    <div class="col-sm-8">
                        <input asp-for="@Model.GrantsViewModel.Grants[i].Granted"
                               class="consent-scopecheck"
                               type="checkbox" />
                        <strong>Granted</strong>
                        <div class="clientname">@Model.GrantsViewModel.Grants[i].ClientName</div>
                        <div>
                            <span class="created">Created:</span> @Model.GrantsViewModel.Grants[i].Created.ToString("yyyy-MM-dd")
                        </div>
                        @if (Model.GrantsViewModel.Grants[i].Expires.HasValue)
                        {
                            <div>
                                <span class="expires">Expires:</span> @Model.GrantsViewModel.Grants[i].Expires.Value.ToString("yyyy-MM-dd")
                            </div>
                        }
                        @if (Model.GrantsViewModel.Grants[i].IdentityGrantNames.Any())
                        {
                            <div>
                                <div class="granttype">Identity Grants</div>
                                <ul>
                                    @foreach (var name in Model.GrantsViewModel.Grants[i].IdentityGrantNames)
                                    {
                                        <li>@name</li>
                                    }
                                </ul>
                            </div>
                        }
                        @if (Model.GrantsViewModel.Grants[i].ApiGrantNames.Any())
                        {
                            <div>
                                <div class="granttype">API Grants</div>
                                <ul>
                                    @foreach (var name in Model.GrantsViewModel.Grants[i].ApiGrantNames)
                                    {
                                        <li>@name</li>
                                    }
                                </ul>
                            </div>
                        }
                    </div>

                </div>
            }
            <div class="form-group">
                <button type="submit" class="btn btn-primary" name="button" value="update" autofocus>Update</button>
                <button type="submit" class="cancel btn btn-default" name="button" value="cancel" CausesValidation="false">Cancel</button>
            </div>
        </form>
    }

</div>